/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.member.web.CsQaaAction
   Module Description   :

   Date Created      : 2010/2/4
   Original Author   : andy.chuang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.member.web;

import java.io.File;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;
import com.yaodian100.core.admin.utils.AdminHelper;
import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.crm.cs.entity.Question;
import com.yaodian100.crm.cs.service.CsService;
import com.yaodian100.ec.member.entity.Balance;
import com.yaodian100.ec.member.entity.ImageValid;
import com.yaodian100.ec.member.service.MemberService;
import com.yaodian100.ec.order.entity.Orders;
import com.yaodian100.ec.product.entity.Product;
import com.yaodian100.mall.member.util.UserData;

/**
 * @author andy.chuang
 *
 */
public class CsQaaAction {
    private String phone;
    private String phoneArea;
    private String phoneExt;
    private String email;
    private String productId;
    private String orderId;
    private String commonQuestionTypeId;
    private String validValue;
    private String description;
    @Resource
    private MemberService memberService;
    @Resource
    private CsService csService;
    @Resource
    private BaseManager baseMgr;
    private String cellPhone;
    private String sysMessage;
    
    private List<File> attach;
	private List<String> attachFileName;
	private List<String> attachContentType;
	private String class1Type;
	
    /**
     * @return the sysMessage
     */
    public String getSysMessage() {
        return sysMessage;
    }

    /**
     * @param sysMessage the sysMessage to set
     */
    public void setSysMessage(String sysMessage) {
        this.sysMessage = sysMessage;
    }

    public String qaa(){
	return "qaa";
    }
    private String page;
    
    /**
     * @return the page
     */
    public String getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(String page) {
        this.page = page;
    }

    public String page(){
	return page;
    }
    public String request(){
	HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
	HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
			ServletActionContext.HTTP_RESPONSE);
	UserData userData = new UserData(request, response);
	if (!checkCode(userData.getImageValid(), validValue)) {
	    sysMessage="验证码错误!!";
	    return "request";
	}else{
	    if(productId!=null && productId.length()>0){
		Product product=(Product)baseMgr.get(Product.class, productId);
		if(product==null){
		    sysMessage="商品编号不存在";
		    return "request";
		}
	    }
	    if(orderId!=null && orderId.length()>0){
		Orders order=(Orders)baseMgr.get(Orders.class, orderId);
		if(order==null){
		    sysMessage="订单编号不存在";
		    return "request";
		}
	    }
	    
	    String memberId=null;
	    if(userData!=null){
		if(userData.getMemberId()!=null)
		memberId=userData.getMemberId();
	    }
	    
	    
	    if (attach == null || attach.size() == 0) {
	    	csService.createCommonQuestion(email, memberId, productId, description, phoneArea, phone, phoneExt, orderId, cellPhone, commonQuestionTypeId);
	    } else {
	    	csService.createCommonQuestion(email, memberId, productId, description, phoneArea, phone, phoneExt, orderId, cellPhone, commonQuestionTypeId, attach, attachFileName);
	    }
	    
	}
	if (class1Type.equals("advice")) {
		return "adviceOK";
	} else if (class1Type.equals("complain")) {
		return "complainOK";
	} else {
		return "requestOK";
	}
	
    }
    private boolean checkCode(String imageId, String inputCode) {
	ImageValid imageValid = new ImageValid();
	imageValid.setId(imageId);
	imageValid.setValidData(inputCode);
	try {
		memberService.isImageValid(imageValid);
	} catch (Exception e) {
		return false;
	}
	return true;
}
    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @return the phoneArea
     */
    public String getPhoneArea() {
        return phoneArea;
    }

    /**
     * @param phoneArea the phoneArea to set
     */
    public void setPhoneArea(String phoneArea) {
        this.phoneArea = phoneArea;
    }

    /**
     * @return the phoneExt
     */
    public String getPhoneExt() {
        return phoneExt;
    }

    /**
     * @param phoneExt the phoneExt to set
     */
    public void setPhoneExt(String phoneExt) {
        this.phoneExt = phoneExt;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the productId
     */
    public String getProductId() {
        return productId;
    }

    /**
     * @param productId the productId to set
     */
    public void setProductId(String productId) {
        this.productId = productId;
    }

    /**
     * @return the orderId
     */
    public String getOrderId() {
        return orderId;
    }

    /**
     * @param orderId the orderId to set
     */
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    /**
     * @return the commonQuestionTypeId
     */
    public String getCommonQuestionTypeId() {
        return commonQuestionTypeId;
    }

    /**
     * @param commonQuestionTypeId the commonQuestionTypeId to set
     */
    public void setCommonQuestionTypeId(String commonQuestionTypeId) {
        this.commonQuestionTypeId = commonQuestionTypeId;
    }

    /**
     * @return the validValue
     */
    public String getValidValue() {
        return validValue;
    }

    /**
     * @param validValue the validValue to set
     */
    public void setValidValue(String validValue) {
        this.validValue = validValue;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the memberService
     */
    public MemberService getMemberService() {
        return memberService;
    }

    /**
     * @param memberService the memberService to set
     */
    public void setMemberService(MemberService memberService) {
        this.memberService = memberService;
    }

    /**
     * @return the cellPhone
     */
    public String getCellPhone() {
        return cellPhone;
    }

    /**
     * @param cellPhone the cellPhone to set
     */
    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

	public CsService getCsService() {
		return csService;
	}

	public void setCsService(CsService csService) {
		this.csService = csService;
	}

	public BaseManager getBaseMgr() {
		return baseMgr;
	}

	public void setBaseMgr(BaseManager baseMgr) {
		this.baseMgr = baseMgr;
	}

	public List<File> getAttach() {
		return attach;
	}

	public void setAttach(List<File> attach) {
		this.attach = attach;
	}

	public List<String> getAttachFileName() {
		return attachFileName;
	}

	public void setAttachFileName(List<String> attachFileName) {
		this.attachFileName = attachFileName;
	}

	public List<String> getAttachContentType() {
		return attachContentType;
	}

	public void setAttachContentType(List<String> attachContentType) {
		this.attachContentType = attachContentType;
	}

	public String getClass1Type() {
		return class1Type;
	}

	public void setClass1Type(String class1Type) {
		this.class1Type = class1Type;
	}
    
    
}
